﻿using OverStore.Runtime.OverStoreContext;
using OverStore.Runtime.ObjectRepository.DeferredLoader;

namespace OverStore.Configuration.ObjectRepository.DeferredLoader
{    
    /// <summary>
    /// Allows to obtain instances of <see cref="InterfaceDeferredLoader{TInstance, TIdentifier}"/> class.
    /// </summary>
    /// <typeparam name="TInstance">The type of instance.</typeparam>
    /// <typeparam name="TIdentifier">The type of identifier.</typeparam>
    public sealed class InterfaceDeferredLoaderConfiguration<TInstance, TIdentifier> : IComponentConfiguration<IDeferredLoader<TInstance>>
        where TInstance : class, IDeferredLoadingSupport
    {
        /// <summary>
        /// Creates the new instance of <see cref="IDeferredLoader{TInstance}"/> type.
        /// </summary>
        /// <param name="currentContext">The current context provides set of services may be used by deffered loader.</param>
        /// <returns>
        /// The new instance of <see cref="IDeferredLoader{TInstance}"/>.
        /// </returns>
        IDeferredLoader<TInstance> IComponentConfiguration<IDeferredLoader<TInstance>>.CreateComponent(IOverStoreContext currentContext)
        {
            return new InterfaceDeferredLoader<TInstance, TIdentifier>(
                currentContext.PersistenceServiceProvider, 
                currentContext.DataStorage);
        }
    }
}
